Skip to content

emrg: TUI status bar shows current context message count (rant 21:52:18) - #772

Merged
argszero merged 1 commit into
masterfrom
feature/tui-context-msg-count
Aug 13, 2026
Merged

emrg: TUI status bar shows current context message count (rant 21:52:18)#772
argszero merged 1 commit into
masterfrom
feature/tui-context-msg-count

Conversation

@argszero

Copy link
Copy Markdown
Owner

Fixes host rant 2026-08-13T21:52:18: the TUI status bar · N msgs · displayed the locally-tracked total message count (including compacted history), which misleads — it should show the number of messages actually sent to the LLM in the current context.

Daemon (emrg/server/daemon.py): every done frame now carries context_messages: len(messages) — the authoritative current-context size (system + history + user + all tool results + assistant replies; re-derived after auto-compact rebuild). Added to both the Case-1 (stop) and Case-3 (max-tokens) final done frames.

TUI (emrg/client/app.py): the done handler sets msg_count = context_messages when present (daemon-authoritative, reflects tool results and auto-compact), falling back to the local +1 approximation otherwise. Status-bar copy unchanged.

Test: test_streaming_task_with_tool_calls extended to assert context_messages == 5 for a one-round tool flow (system + user + assistant-tool_calls + tool-result + final assistant).

Verified: pytest 801/801, import + CLI OK. GUI untouched.

The status bar '· N msgs ·' showed the locally-tracked total message count
(including compacted history), not the actual messages sent to the LLM.
Daemon now reports the authoritative current-context size on every done
frame (system + history + user + tool results + assistant replies, rebuilt
after auto-compact) via context_messages; TUI uses it instead of the +1
local approximation (falls back to +1 when absent). +1 e2e test asserting
context_messages == 5 for a one-round tool flow (system+user+assistant-tool
+tool-result+assistant).

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle (1/3)

Verified head 32442e1 (3 files, +21/-1):

  • daemon.py: both final done frames (Case 1 stop @2271, Case 3 max-tokens @2445) now carry context_messages: len(messages) — authoritative current-LLM-context size (system + history + user + tool results + assistant replies), correctly re-derived after auto-compact rebuild (messages rebuilt @2170).
  • app.py done handler: msg_count = int(context_messages) when present, +1 fallback otherwise; status-bar copy unchanged (· N msgs · path).
  • e2e test: one-round tool flow asserts context_messages == 5 (system + user + assistant-tool_calls + tool-result + final assistant) — matches the actual message flow (initial 2, +assistant_msg@2313, +tool result@2397, +final assistant@2435).
  • pytest 801/801 local, CI test + test-windows PASS (run 31708272704).

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle (2/3)

Re-verified head 32442e1 (unchanged since 1/3):

  • Diff vs master 44b09d8 = 3 files +21/-1: daemon.py adds context_messages: len(messages) to both final done frames (Case 1 stop, Case 3 max-tokens); app.py consumes it with +1 fallback; e2e asserts context_messages == 5 for the one-round tool flow.
  • No overlap with the #771 GUI merge (daemon/app/test files vs GUI files) — no rebase needed, MERGEABLE.
  • CI test + test-windows PASS (run 31708272704).

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle (2/3, head 32442e1)

Fresh independent verification this cycle:

  • daemon.py: BOTH final done frames now carry context_messages: len(messages) — Case 1 (loop exit @~2277) and Case 3 (max-tokens @~2455) — authoritative current LLM context (system + history + user + tool results + assistant replies), correctly re-derived after auto-compact rebuild.
  • app.py done handler: int(context_messages) when present, +1 local fallback otherwise (backward compatible with older daemons); status-bar copy unchanged.
  • e2e test test_streaming_task_with_tool_calls: asserts context_messages == 5 (system + user + assistant-tool_calls + tool-result + final assistant) — ran locally: 1 passed.
  • CI test + test-windows PASS (run 31708272704); branch = 3 files (+21/-1), based on master 44b09d8.

@argszero
argszero merged commit 66ab9a0 into master Aug 13, 2026
2 checks passed
argszero added a commit that referenced this pull request Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant